#include "ros/ros.h"
#include "service_pkg/person.h"

int main(int argc, char **argv)
{
    ros::init(argc, argv, "person_client");

    ros::NodeHandle node;

    //等待发现/show_person服务节点
    ros::service::waitForService("/show_person");   //阻塞
    //发现/show_person服务节点则与其建立链接
    ros::ServiceClient person_client = node.serviceClient<service_pkg::person>("/show_person");

    //初始化待发送的service请求数据
    service_pkg::person srv;
    srv.request.name = "Tom";
    srv.request.age = 20;
    srv.request.gender = service_pkg::person::Request::male;

    ROS_INFO("Call service to show person[name:%s, age:%d, gender:%d]",
     srv.request.name.c_str(), srv.request.age, srv.request.gender);
    
    //请求服务调用
    person_client.call(srv);

    //显示服务调用结果
    ROS_INFO("Show person result: %s", srv.response.result.c_str());

    return 0;
}


